<template>
    <div ref="rightPanel" :class="{show:isPopups}" class="m-popups">
      <div class="m-popups-bg"></div>
      <div class="m-popups-box">
        <div class="f-title">
          <p>{{title}}</p>
          <i class="el-icon-close" @click="closePopups"></i>
        </div>
        <div v-if="typeId == 1" class="f-content">
          <el-form :model="menuForm" :rules="menuRules" ref="menuForms" label-width="80px">
            <el-form-item label="所属系统">
              <el-radio-group v-model="menuForm.menuType">
                <el-radio label="2">管理平台</el-radio>
                <el-radio label="1">品牌</el-radio>
                <el-radio label="0">商户</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="名称" prop="menuName">
              <el-input class="inputWidth" v-model="menuForm.menuName" placeholder="请输入名称"></el-input>
            </el-form-item>
            <el-form-item label="实体名称">
              <el-input class="inputWidth" v-model="menuForm.menuIcon" placeholder="请输入实体名称"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="onSubmit">确认</el-button>
              <el-button @click="closePopups">取消</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
</template>

<script>
import { reactive, ref, toRefs, watch, computed } from "vue"
import { menuTree, menuAdd, dataInterfacePage } from '@/api/menu'
import { ElMessage } from 'element-plus'
import { useRoute, useRouter } from 'vue-router'

export default {
  name: 'AuthPopups',
  props: {
    isPopups: Boolean,
    typeId: Number,
    menuId: Number
  },
  setup(props, context) {
    const menuForms = ref(null)
    const route = useRoute()
    const router = useRouter()
    const state = reactive({
      menuForm: {
        menuType: '2',
        menuIcon:"",
        menuName:""
      },
      menuRules: {
        parentMenuId: [{ required: true, message: '请选择父级权限', trigger: 'blur' }],
        menuName: [{ required: true, message: '请输入权实体名称', trigger: 'blur' }]
      },
      parentMenu: [],
      columnList: []
    })
    watch(()=>props.isPopups,(newProps, oldProps) => {
      if (newProps && props.typeId == 1) {
        menuTree().then((res) => {
          if(res.code === 200){
            state.parentMenu = res.data.data 
          }
        })
      } else if (newProps && props.typeId == 3) {
        dataInterfacePage().then((res) => {
          if(res.code === 200){
            state.columnList = res.data.data  
          }
        })
      }
    })
    const title = computed(()=>{
      if (props.typeId == 1) {
        return '新增数据权限'
      } else if (props.typeId == 2) {
        return '修改数据权限'
      }
    })
    const closePopups = () => {
      const isPopups = false
      context.emit('closePop', isPopups)
    }
    const onSubmit = () => {
      let obj = {
        systemCode:state.menuForm.menuType,
        tableName:state.menuForm.menuIcon,
        tagGroupName:state.menuForm.menuName
      }
      context.emit('submit',obj)
      // menuForms.value.validate((valid) => {
      //   if (valid) {
      //     if (props.typeId == 1) {
            
      //     }
      //   } else {
      //     return false
      //   }
      // })
    }
    return {
      ...toRefs(state),
      title,
      menuForms,
      closePopups,
      onSubmit
    }
  }
}
</script>

<style>
.showRightPanel {
  overflow: hidden;
  position: relative;
  width: calc(100% - 15px);
}
</style>

<style lang="less" scoped>
.m-popups {
  .m-popups-bg {
    position: fixed;
    top: 0;
    left: 0;
    opacity: 0;
    transition: opacity .3s cubic-bezier(.7, .3, .1, 1);
    background: rgba(0, 0, 0, .6);
    z-index: -1;
  }
  .m-popups-box {
    width: 100%;
    max-width: 1000px;
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0;
    box-shadow: 0px 0px 15px 0px rgba(0, 0, 0, .05);
    transition: all .25s cubic-bezier(.7, .3, .1, 1);
    transform: translate(100%);
    background: #fff;
    z-index: 11;
    border-radius: 26px 0 0 26px;
    .f-title {
      display: flex;
      width: 90%;
      height: 60px;
      margin: 0 auto 30px;
      justify-content: space-between;
      align-items: center;
      border-bottom: 1px solid #cccccc;
      p {
        font-size: 16px;
      }
      i {
        cursor: pointer;
        font-size: 16px;
      }
    }
    .f-content {
      width: 90%;
      height: 80%;
      margin: 0 auto 12px;
      padding: 12px;
      font-size: 14px;
      overflow: auto;
      overflow-x: hidden;
      box-sizing: border-box;
    }
    .f-btn {
      width: 90%;
      margin: 0 auto;
      text-align: right;
    }
  }
  .inputWidth {
    width: 300px;
  }
}
.show {
  transition: all .6s cubic-bezier(.7, .3, .1, 1);

  .m-popups-bg {
    z-index: 10;
    opacity: 1;
    width: 100%;
    height: 100%;
  }

  .m-popups-box {
    transform: translate(0);
  }
}
</style>
